<?php
namespace app\model;

class UrlScheme{

    public static function getUrlScheme($system,$postData)
    {
        $appid = $postData['appid'];
        $appsecret = $postData['appsecret'];
        $is_expire = $postData['is_expire'];
        $expire_time = $postData['expire_time'];
        $jump_wxa = $postData['jump_wxa'];
//
//        $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret=' . $appsecret;
//        $res = json_decode(file_get_contents($url),true);
//        $access_token = $res['access_token'];

        $access_token = getAccessToken($system);

        //请求url
        $url = 'https://api.weixin.qq.com/wxa/generatescheme?access_token=' . $access_token ;
        //发送内容
        $data = [] ;
        $data['jump_wxa']=$jump_wxa;
        $data['is_expire']=$is_expire;
        $data['expire_time']=$expire_time;
        return json_decode(self::curlPost($url,json_encode($data)),true);
    }

    /**
     * Desc:发送post请求
     * User: cbw
     * Time: 2020/12/31 4:36 下午
     * @param $url
     * @param $data
     * @return bool|string
     */
    public static function curlPost($url,$data)
    {
        $ch = curl_init();
        $params[CURLOPT_URL] = $url;    //请求url地址
        $params[CURLOPT_HEADER] = FALSE; //是否返回响应头信息
        $params[CURLOPT_SSL_VERIFYPEER] = false;
        $params[CURLOPT_SSL_VERIFYHOST] = false;
        $params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
        $params[CURLOPT_POST] = true;
        $params[CURLOPT_POSTFIELDS] = $data;
        curl_setopt_array($ch, $params); //传入curl参数
        $content = curl_exec($ch); //执行
        curl_close($ch); //关闭连接
        return $content;
    }
}